package com.flashextended.apps.logomaker.view.windows.properties
{
	import com.flashextended.apps.logomaker.beans.workareaobjects.GenericObject;
	import com.flashextended.apps.logomaker.beans.workareaobjects.ImageOnStage;
	import com.flashextended.apps.logomaker.beans.workareaobjects.SymbolOnStage;
	import com.flashextended.apps.logomaker.beans.workareaobjects.TextOnStage;
	import com.flashextended.apps.logomaker.singleton.AppControl;
	import com.flashextended.apps.logomaker.singleton.AppLocales;
	import com.flashextended.apps.logomaker.view.windows.properties.content.GenericPropertiesContent;
	import com.flashextended.apps.logomaker.view.windows.properties.content.ImagePropertiesContent;
	import com.flashextended.apps.logomaker.view.windows.properties.content.SymbolPropertiesContent;
	import com.flashextended.apps.logomaker.view.windows.properties.content.TextPropertiesContent;
	import com.flashextended.utils.graphics.windows.GenericInfoWindow;
	
	import mx.events.EffectEvent;

	public class GenericProperties extends GenericInfoWindow
	{
		private var currentObject:GenericObject;
		private var currentId:int;
		
		private static var currentTYPE:String="NONE";
		
		private var oldX:Number=0;
		private var oldY:Number=0;
		
		private var propertiesContent:GenericPropertiesContent;
		
		public function GenericProperties(w:Number, h:Number, title:String="Info")
		{
			super(w, h, title);
			this.removeChild(this.getFooter());
		}
		
		override public function closeWindow(e:EffectEvent=null):void
		{
			this.visible = false;
			this.x = oldX;
			this.y = oldY;
		}
		
		public function openProperties(o:GenericObject):void
		{
			if(!this.visible)
			{
				this.alpha = 1;
				this.visible = true;
			}
			if(currentObject == o)
			{
				//return;
			}
			if(o.type == ImageOnStage.TYPE)
			{
				if((currentTYPE != o.type) || (o.idObject!=currentId))
				{
					removeContent();
					propertiesContent = new ImagePropertiesContent();
					this.getContentPane().addChild(propertiesContent);					
					this.w = 468;
					this.h = 150;
					show();
				}
				this.title = AppLocales.getInstance().data.locales["imageProp"];
			}
			else if(o.type == TextOnStage.TYPE)
			{
				if((currentTYPE != o.type) || (o.idObject!=currentId))
				{
					removeContent();
					propertiesContent = new TextPropertiesContent();
					this.getContentPane().addChild(propertiesContent);					
					this.w = 390;
					this.h = 230;
					show();		
				}
				this.title = AppLocales.getInstance().data.locales["textProp"];
			}
			else if(o.type == SymbolOnStage.TYPE)
			{
				if((currentTYPE != o.type) || (o.idObject!=currentId))
				{
					removeContent();
					propertiesContent = new SymbolPropertiesContent();
					this.getContentPane().addChild(propertiesContent);	
					this.w = 300;
					this.h = 180;
					show();					
				}
				this.title = AppLocales.getInstance().data.locales["symbolProp"];
			}
			currentTYPE = o.type;
			AppControl.getInstance().workarea.checkUpDownAvailability();
			currentId = o.idObject;
		}
		
		private function removeContent():void
		{
			try{
				this.getContentPane().removeChild(propertiesContent);
				propertiesContent = null;
			}catch(e:Error)
			{
				trace(e.message);
			}
		}
		
		public function closeProperties():void
		{
			oldX = this.x;
			oldY = this.y;
			currentTYPE = "NONE";
			this.cancelMouseHandler();
		}
		
		//Opperations - Incomming calls from Workarea
		public function upMovementAvailable(val:Boolean=true):void
		{
			propertiesContent.getUpButton().enabledButton = val;
		}
		public function downMovementAvailable(val:Boolean=true):void
		{
			propertiesContent.getDownButton().enabledButton = val;
		}
		
	}
}